var http = require("http");
var url = require("url");
 
function start(route) {
  function onRequest(request, response) {
    var pathname = url.parse(request.url).pathname;
    console.log("Request for " + pathname + " received.");
    try{
      // response.write(route(pathname));
      route(pathname)
      // console.log(route(pathname),'??????????????')
    } catch (e) {
      console.log(111111111111111)
    }
    

    // console.log(response)
    response.writeHead(200, {"Content-Type": "text/plain"});
    response.write("Hello World");
    response.end();
  }
 
  var server = http.createServer(onRequest).listen(8888, function () {
 
    var host = server.address().address
    var port = server.address().port
   
    console.log("应用实例，访问地址为 http://%s:%s", host, port)
   
  });
  console.log("Server has started.");
}
 
exports.start = start;